

// 字符串分割函数的测试
#include <iostream>
#include <string>
#include <vector>

size_t split(const std::string &str, const std::string &sep, std::vector<std::string> &result)
{
    size_t idx = 0;
    size_t pos = 0;

    while (idx < str.size())
    {
        pos = str.find(sep, idx);
        if (pos == std::string::npos)
        {
            result.push_back(str.substr(idx));
            return result.size();
        }
        if (pos == idx)
        {
            idx = pos + sep.size();
            continue;
        }
        std::string tmp = str.substr(idx, pos - idx);
        result.push_back(tmp);
        idx = pos + sep.size();
    }
    return result.size();
}

int main()
{
    std::string str = "...new...music.#..sport...";
    std::vector<std::string> arr;
    size_t n = split(str, ".", arr);
    std::cout << n << std::endl;

    for (auto &s : arr)
        std::cout << s << std::endl;
    return 0;
}